package top.yongyan0624.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author Yongyan
 * @description: TODO
 * @date 2021/5/10
 **/
/*
 * 前后端分离项目需要处理跨域问题：全局配置类配置跨域请求
 * */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  //允许所有请求跨域
                .allowedOrigins("Http://localhost:8080", null) //请求来源
                .allowedMethods("GET", "POST", "PUT", "OPTIONS", "DELETE") //方法
                .allowCredentials(true) //是否允许携带token等信息
                .maxAge(3600);  //响应时间
    }
}
